﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HR.ProjectX.DAL.UnitOfWork;
using NHibernate;
using HR.ProjectX.DAL.SessionStorage;
using HR.ProjectX.Models.Entities.Vehicles;

namespace HR.ProjectX.DAL.Repositories
{
    public class ManufacturerRepository : Repository<Manufacturer, int>, IManufacturerRepository
    {
        public ManufacturerRepository(IUnitOfWork uow)
            : base(uow)
        {
        }

        public Manufacturer FindManufacturerByName(string manufacturerName)
        {
            ICriteria criteriaQuery = SessionFactory.GetCurrentSession()
                    .CreateCriteria(typeof(Manufacturer))
                    .Add(NHibernate.Criterion.Restrictions.Eq("ManufacturerName", manufacturerName));

            return (Manufacturer)criteriaQuery.List<Manufacturer>().FirstOrDefault();
        }
    }
}
